#!/bin/bash
# MR_STATUS="CANMERGE"
# MR_TARGET_BRANCH="main1"
# CANMERGE
# ACCEPTED

content='DEFAULT CONTENT'
MINIPROGRAM_NAME="MINIPROGRAM_NAME"

if [ $MR_TARGET_BRANCH = 'main' ]; then
  MINIPROGRAM_NAME="校园助手"
elif [ $MR_TARGET_BRANCH = 'main-cloud-intelligence' ]; then
  MINIPROGRAM_NAME="校园IOT超级管家"
else
  exit 0
fi

if [[ $MR_STATUS =~ "MERGE" ]]; then
  content="$MR_SOURCE_BRANCH分支向$MR_TARGET_BRANCH分支发起了合并请求,预计今天《$MINIPROGRAM_NAME》小程序将有上线计划，请所有人知晓!"

elif [ $MR_STATUS = "ACCEPTED" ]; then

  content="$MR_SOURCE_BRANCH分支已经合并入$MR_TARGET_BRANCH分支,《$MINIPROGRAM_NAME》小程序即将进行发布，请相关成员重点关注!"

else
  echo "nothing"

fi

if [ $content ]; then

  curl 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=3764ec69-983d-45ec-bc20-682f7245796e' \
    -H 'Content-Type: application/json' \
    -d '
{
"msgtype": "text",
"text": {
"content": "'$content'",
"mentioned_mobile_list":["@all"]
}
}'
fi
